package com.nursinghome.admin.controller;

import com.nursinghome.admin.service.MedicalStaffService;
import com.nursinghome.bean.Category;
import com.nursinghome.bean.RespBean;
import com.nursinghome.common.service.CategoryService;
import com.nursinghome.exception.NurisingHomeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private MedicalStaffService medicalStaffService;
    //获取到所有的分类
    @GetMapping
    public RespBean selectAll(Integer pageNum, Integer pageSize, Category category) {
        Object categories = categoryService.selectAll(pageNum, pageSize, category);

        return RespBean.ok("",categories);
    }
    //新增分类
    @PostMapping
    public RespBean insert(@RequestBody Category category) throws NurisingHomeException {
        if (categoryService.insert(category)) {
            return RespBean.ok("新增成功");
        }
        return RespBean.error("新增失败");
    }
    //修改分类
    @PutMapping
    public RespBean update(@RequestBody Category category) throws NurisingHomeException {
        if (categoryService.update(category)) {
            return RespBean.ok("修改成功");
        }
        return RespBean.error("修改失败");
    }
    //删除分类
    @DeleteMapping("/{id}")
    public RespBean del(@PathVariable("id") Integer id) throws NurisingHomeException {
        if (categoryService.delete(id)) {
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    //回显分类数据
    @GetMapping("/{id}")
    public RespBean selectById(@PathVariable("id") Integer id) throws NurisingHomeException {
        Category category = categoryService.selectById(id);
        return RespBean.ok("",category);
    }

}
